const { defineConfig } = require('@vue/cli-service')
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const path = require('path');
const TITLE = process.env.VUE_APP_TITLE
const scss_path = `@/assets/theme/index.scss`
const timeStamp = new Date().getTime()
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  productionSourceMap: false,
  configureWebpack: config=>{
    config.output.filename =`js/[name].[contenthash].js?v=${timeStamp}`,
    config.output.chunkFilename =`js/[name].[contenthash].js?v=${timeStamp}`,
    config.plugins.push(new NodePolyfillPlugin())
  },
  //publicPath: './',//打包用
  publicPath: '/wap/', //H5网页用
  outputDir: 'dist',
  assetsDir: '',
  chainWebpack: config => {
    config.plugin('html')
      .tap(args => {
        args[0].title = TITLE
        return args
      })
  },
  css: {
    loaderOptions: {
      scss: {
        additionalData: `@import "${scss_path}";`
      },
    }
  },
  devServer: {
    port: 8090,
    host: '0.0.0.0',
    https: false,
    open: true,
    proxy: {
      // 可为不同的接口配置不同的代理地址
      '/wap/api': {
        // 服务地址，即你要访问的服务器地址
        target: 'https://hajhiug.com/wap/',
        // 路径重写，将'/user/login'重写为'/login'
        pathRewrite: {
          '^/wap/api': ''
        },
        // 所有信息都在命令行工具打印
        logLevel: 'debug'
      },
    },
    client: {
      overlay: false
    }
  }
})
